Remember method/static call expression as truthy/falsey alongside @phpstan-assert-if-true argument narrowing#5880
Merged
staabm merged 28 commits intoJun 17, 2026
Conversation
staabm
reviewed
Jun 15, 2026
ce1888f to
181e6e9
Compare
969b695 to
70fb90a
Compare
ff8ea80 to
24126c3
Compare
staabm
requested changes
Jun 16, 2026
staabm
left a comment
Contributor
There was a problem hiding this comment.
after this PR the snippet https://phpstan.org/r/9eb23e31-92a3-41e0-9f85-731ee7f3f5b2 runs endless
staabm
requested changes
Jun 16, 2026
staabm
left a comment
Contributor
There was a problem hiding this comment.
fix this endless loop
https://gist.github.com/ondrejmirtes/6ab9c2e53be1c112b3ee1120c6c89aea
…if-true` argument narrowing
- When a function/method/static call carries `@phpstan-assert*` assertions, the
call handlers previously returned only the assert-specified argument narrowing
and skipped `handleDefaultTruthyOrFalseyContext`, so the call expression itself
was not remembered as truthy/falsey in the branch. Re-evaluating it (e.g.
`if (is_readable($p)) { require $p; }`) then yielded `bool` instead of `true`.
- `FuncCallHandler`, `MethodCallHandler` and `StaticCallHandler` now union the
asserts result with the default truthy/falsey narrowing, while preserving the
asserts' original root expression so impossible-check detection is unaffected.
- `ImpossibleCheckTypeHelper` now ignores the self-referential narrowing entry
(the checked call expression itself), which carries no information about
whether the check is redundant — the informative narrowing lives in the
argument entries.
- `RequireFileExistsRule` additionally treats `is_readable`, `is_writable`,
`is_writeable` and `is_executable` (next to `file_exists`/`is_file`) as guards
that prove the path exists, via a named `FILE_EXISTENCE_FUNCTIONS` constant.
- Fixed a genuine `X && !X` bug in the build-only
`OrChainIdenticalComparisonToInArrayRule::getSubjectAndValue()` that the
improved narrowing newly detects.
9c4e11c to
77b8552
Compare
staabm
approved these changes
Jun 16, 2026
Collaborator
Author
|
This pull request has been marked as ready for review. |
@phpstan-assert-if-true argument narrowing@phpstan-assert-if-true argument narrowing
VincentLanglet
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
similar to #5885 but for
MethodCallandStaticCall